from pyspark.context import SparkContext
import json

sc = SparkContext(master='local',appName='word_count')

ints = [1,2,3,4,5,6,7,8,9]

rdd1 = sc.parallelize(ints)

rdd2 = rdd1.map(lambda x: x ** 2)
rdd2.foreach(print)



students_josn_rdd = sc.textFile('../../data/students.json')

def student_pas(stu_json):
    stu_dict = json.loads(stu_json)
    id = stu_dict.get('id')
    name = stu_dict.get('name')
    age = stu_dict.get('age')
    gender = stu_dict.get('gender')
    clazz = stu_dict.get('clazz')

    clazz_type = clazz[:2]

    return id ,name, age, gender, clazz, clazz_type


students_rdd = students_josn_rdd.map(student_pas)

students_rdd.foreach(print)